<%--
  作者:张伟

  联系:adamzzww@163.com
  时间:2016-11-30
  说明:无
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>菜单选择树</title>
    <%@include file="../../desktop/include/assets.jsp" %>
    <link href="<%=_asset_path%>/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet">
    <script type="text/javascript" src="<%=_asset_path%>/ztree/jquery.ztree.all.min.js"></script>
    <%
        String url = request.getContextPath() + Global.PATH + "/menu";
    %>
    <script type="text/javascript">
        var setting = {
            view: {
                selectedMulti: true
            },
            check: {
                enable: true,
                //chkStyle: "radio",//修改了这里
                chkboxType: {"Y": "ps", "N": "ps"},
                //radioType: "all"
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pId"
                }
            },
            async: {
                type: "get",
                enable: true,
                url: "<%=url%>/tree?roleId=${roleId}",
                autoParam: ["id", "name"]
            }
        };

        var zNodes = [];

        //获取所选节点
        function getSelectedNodes() {
            var menuId = "";
            var menuName = "";
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            var selectedNode = treeObj.getCheckedNodes(true);
            for (var i = 0; i < selectedNode.length; i++) {
                menuId = menuId + selectedNode[i].id + ";";
                menuName = menuName + selectedNode[i].name + ";";
            }
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.$('#menusId').val(menuId);
            parent.$('#menusName').val(menuName);
            parent.layer.close(index);

        }

        $(function () {
            $.fn.zTree.init($("#tree"), setting, zNodes);

            $('#save').click(function () {
                getSelectedNodes();
            });
        });

    </script>
</head>
<body>
<div style="padding:10px;">
    <ul id="tree" class="ztree" style="margin-top:0px;width:auto;"></ul>
    <hr/>
    <ul style="margin-top:5px;margin-bottom:5px;">
        <input style="margin-right:10px;float:right;" type="button" id="save" value="保存"/>
        <div style="clear:both"></div>
    </ul>

</div>
</body>
</html>
